﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

public partial class Pages_Dashboard_Account_Edit : System.Web.UI.Page, ICrumbedPage
{
	public int AccountID
	{
		get
		{
			int temp;
			int.TryParse(Request["ID"], out temp);
			return temp;
		}
	}
	protected BO.User User;
	protected BO.Account Account;
	private void Authenicate()
	{
		if (Authentication.IsCurrentUserAuthenticated())
			User = Authentication.GetCurrentUser();

		if (User == null)
			Response.Redirect("/default.aspx");

		Account = BO.Account.GetWithMaster(AccountID);

		if (Account == null || Account.MasterAccount.ProfileID != User.ProfileID)
			Response.Redirect("/default.aspx");
	}

    protected void Page_Load(object sender, EventArgs e)
    {
		Authenicate();
		if(!IsPostBack)
			LoadData();
    }

	private void LoadData()
	{
		ucAccountSideMenu.AccountID = AccountID;
		tbName.Text = Account.Name;
	}

	protected void lbtnSave_Click(object sender, EventArgs e)
	{
		Account.Name = tbName.Text;
		Account.Update();

	}

	#region ICrumbedPage Members

	public int Level
	{
		get { return 4; }
	}

	public string TailName
	{
		get { return "Edit"; }
	}

	#endregion
}